package com.example.dmdomain;

import com.example.dmdomain.entity.ChatSession;
import com.example.dmdomain.entity.SystemChatSession;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;


@Repository
public interface SystemChatSessionRepository extends JpaRepository<SystemChatSession, String>, JpaSpecificationExecutor<SystemChatSession> {

    @Query(value = "select * from system_chat_session where request_id= :requestId and del_state = 0", nativeQuery = true)
    List<SystemChatSession> findByRequestId(@Param("requestId") String requestId);

    @Query(value = "select * from system_chat_session where use_id= :userId and del_state = 3 and system_name = :systemName order by session_time desc", nativeQuery = true)
    List<SystemChatSession> findAllByUserId(@Param("userId") String userId,@Param("systemName") String systemName);

    @Query(value = "select * from system_chat_session where session_id= :sessionId and system_name = :systemName ", nativeQuery = true)
    List<SystemChatSession> findAllBySessionId(@Param("sessionId") String sessionId,@Param("systemName") String systemName);
}
